//
//  ConvertModel.m
//  WeChatMoments
//
//  Created by Jiang on 2019/8/25.
//  Copyright © 2019 SilverFruity. All rights reserved.
//

#import "ConvertModel.h"

@implementation ConvertModel
+ (NSArray *)models:(NSArray *)array{
    return [array map:^id(NSUInteger index, id Object) {
        return [self model:Object];
    }];
}
+ (instancetype)model:(NSDictionary *)dictionary{
    return [self yy_modelWithDictionary:dictionary];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
    [self yy_modelEncodeWithCoder:aCoder];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    return [[super init] yy_modelInitWithCoder:aDecoder];
}
+ (id)modelWithObject:(id)object{
    if ([object isKindOfClass:[NSDictionary class]]) {
        return [[self class] model:object];
    }else if ([object isKindOfClass:[NSArray class]]){
        return [[self class] models:object];
    }else{
        return nil;
    }
}
- (NSString *)description{
    return [self yy_modelDescription];
}
+ (id <SFHTTPConvertModel>)convert2Model:(id)data error:(NSError **)error{
    if ([data isKindOfClass:[NSData class]]) {
        data = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:error];
    }
    return [self modelWithObject:data];
}
@end
